package com.encyclopedia.controller;

import com.encyclopedia.domain.PlantCrop;
import com.encyclopedia.result.JsonRequest;
import com.encyclopedia.service.PlantCropService;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author MaLiang
 * @version 1.0
 * @date 2024-05-05 5:58
 */
@RestController
@RequestMapping("/admin/crop")
public class PlantCropController {


    @Autowired
    private PlantCropService plantCropService;

    @GetMapping("/cropAll")
    private JsonRequest getInfo(PlantCrop plantCrop){
        return plantCropService.getCropInfo(plantCrop);
    }

    @PostMapping
    public int insertCrop(@RequestBody PlantCrop plantCrop){
        return plantCropService.insertCrop(plantCrop);
    }


    @DeleteMapping("/{id}")
    public int deleteCrop(@PathVariable("id") Long id){
        return plantCropService.deleteCrop(id);
    }


    //修改
    @GetMapping("/{cropId}")
    public JsonRequest updateCrop(@PathVariable("cropId") Long id){
        return plantCropService.getInfoId(id);
    }
    @PutMapping
    public int updateCrop(@RequestBody PlantCrop plantCrop){
        return plantCropService.updateCrop(plantCrop);
    }
}
